package www.openteam.com.model.qualityCntrl;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
import www.openteam.com.base.BaseModel;
import www.openteam.com.bean.IQCCheckItem;
import www.openteam.com.bean.IQCDefectdItem;

/**
 * Created by Administrator on 2018/3/1 0001.
 */

public class IQC00Model extends BaseModel {

    public void findCheckItem( final IQC00Model.CheckItemListener listener){
        httpApiService.findIQCCheckItem().subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<IQCCheckItem>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        listener.fail(e);
                    }

                    @Override
                    public void onNext(IQCCheckItem iqcCheckItem) {
                        listener.success(iqcCheckItem);
                    }
                });
    }

    public void findDefectsItem(String code, final IQC00Model.DefectsItemListener listener){
        httpApiService.findDefectsItem(code).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<IQCDefectdItem>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        listener.fail(e);
                    }

                    @Override
                    public void onNext(IQCDefectdItem iqcDefectdItem) {
                        listener.success(iqcDefectdItem);
                    }
                });
    }



    public interface CheckItemListener{

        void success(IQCCheckItem iqcCheckItem);

        void fail(Throwable e);
    }

    public interface DefectsItemListener{

        void success(IQCDefectdItem iqcDefectdItem);

        void fail(Throwable e);
    }
}
